package view;

import java.awt.Toolkit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.RandomAccessFileOrArray;
import com.itextpdf.text.pdf.codec.GifImage;
import com.itextpdf.text.pdf.codec.TiffImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JTextArea;



public class MainGraficoBotonSaveAs2PDF {

    public static void main(String[] args) {
        try {
            
        	OutputStream file = new FileOutputStream(new File("C:\\Temp\\Test.pdf"));
            Document document = new Document();
            PdfWriter.getInstance(document, file);
            document.open();
        
         /* Version solo texto    
            document.add(new Paragraph("Hola a todos!"));
            document.add(new Paragraph(new Date().toString()));

            document.close();
            file.close();
         */
            
         
          /* Ejemplo para imprimir tablas INI 
           PdfPTable table = new PdfPTable(2); // Code 1
           
    		// Code 2
    		table.addCell("1");
    		table.addCell("2");
    		
    		// Code 3
    		table.addCell("3");
    		table.addCell("4");
    		
    		// Code 4
    		table.addCell("5");
    		table.addCell("6");
    		
    		// Code 5
    		document.add(table);		
    		document.close();
    		 Ejemplo para imprimir tablas FIN */
    		
    		// Code 1
    		document.add(new Paragraph("Simple Image"));
    		Image image = Image.getInstance("mouse.jpg");
    		document.add(image);
    		
    		
    		
    		
    	/*	
    		// Code 2
    		document.add(new Paragraph("\n"+"AWT Image"));
    		Image awtImg = Toolkit.getDefaultToolkit().createImage("square.jpg");
    		Image image2 = Image.getInstance(awtImg, null);
    		document.add(image2);				
    		document.newPage();
    		
        */
    		// Code 3
    		document.add(new Paragraph("Multipages tiff file"));
    		RandomAccessFileOrArray ra = 
    			new RandomAccessFileOrArray("multipage.tif");
    		int pages = TiffImage.getNumberOfPages(ra);
    		for(int i = 1; i <= pages; i++){
    			document.add(TiffImage.getTiffImage(ra, i));
    		}		
    		document.newPage();
    		
    		// Code 4
    		document.add(new Paragraph("Animated Gifs"));
    		GifImage img = new GifImage("bee.gif");
    		int frame_count = img.getFrameCount();
    		for(int i = 1; i <= frame_count; i++){
    			document.add(img.getImage(i));
    		}
    		document.close();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}